| Conditions | 15 |
| Paths | 113 |
| Total Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like PromisesUserPopulator.folderResponseParseRec often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | |||
| 56 | PromisesUserPopulator.prototype.folderResponseParseRec = function(sNamespace, aFolders, expandedFolders) |
||
| 57 | { |
||
| 58 | var |
||
| 59 | self = this, |
||
| 60 | iIndex = 0, |
||
| 61 | iLen = 0, |
||
| 62 | oFolder = null, |
||
|
|
|||
| 63 | oCacheFolder = null, |
||
| 64 | bDisplaySpecSetting = FolderStore.displaySpecSetting(), |
||
| 65 | sFolderFullNameRaw = '', |
||
| 66 | aSubFolders = [], |
||
| 67 | aList = []; |
||
| 68 | |||
| 69 | for (iIndex = 0, iLen = aFolders.length; iIndex < iLen; iIndex++) |
||
| 70 | { |
||
| 71 | oFolder = aFolders[iIndex]; |
||
| 72 | if (oFolder) |
||
| 73 | { |
||
| 74 | sFolderFullNameRaw = oFolder.FullNameRaw; |
||
| 75 | |||
| 76 | oCacheFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw); |
||
| 77 | if (!oCacheFolder) |
||
| 78 | { |
||
| 79 | oCacheFolder = FolderModel.newInstanceFromJson(oFolder); |
||
| 80 | if (oCacheFolder) |
||
| 81 | { |
||
| 82 | Cache.setFolderToCacheList(sFolderFullNameRaw, oCacheFolder); |
||
| 83 | Cache.setFolderFullNameRaw(oCacheFolder.fullNameHash, sFolderFullNameRaw, oCacheFolder); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | if (oCacheFolder) |
||
| 88 | { |
||
| 89 | if (bDisplaySpecSetting) |
||
| 90 | { |
||
| 91 | oCacheFolder.checkable(!!oFolder.Checkable); |
||
| 92 | } |
||
| 93 | else |
||
| 94 | { |
||
| 95 | oCacheFolder.checkable(true); |
||
| 96 | } |
||
| 97 | |||
| 98 | oCacheFolder.collapsed(!self.isFolderExpanded(oCacheFolder.fullNameHash, expandedFolders)); |
||
| 99 | |||
| 100 | if (oFolder.Extended) |
||
| 101 | { |
||
| 102 | if (oFolder.Extended.Hash) |
||
| 103 | { |
||
| 104 | Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (Utils.isNormal(oFolder.Extended.MessageCount)) |
||
| 108 | { |
||
| 109 | oCacheFolder.messageCountAll(oFolder.Extended.MessageCount); |
||
| 110 | } |
||
| 111 | |||
| 112 | if (Utils.isNormal(oFolder.Extended.MessageUnseenCount)) |
||
| 113 | { |
||
| 114 | oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | aSubFolders = oFolder.SubFolders; |
||
| 119 | if (aSubFolders && 'Collection/FolderCollection' === aSubFolders['@Object'] && |
||
| 120 | aSubFolders['@Collection'] && Utils.isArray(aSubFolders['@Collection'])) |
||
| 121 | { |
||
| 122 | oCacheFolder.subFolders( |
||
| 123 | this.folderResponseParseRec(sNamespace, aSubFolders['@Collection'], expandedFolders)); |
||
| 124 | } |
||
| 125 | |||
| 126 | aList.push(oCacheFolder); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | return aList; |
||
| 132 | }; |
||
| 133 | |||
| 209 |